{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1b012394",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.6.0\n"
     ]
    }
   ],
   "source": [
    "# import tensorflow as tf\n",
    "import mindspore as tf\n",
    "print(tf.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7dc17f76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(2, 2), dtype=float32, numpy=\n",
       "array([[7., 3.],\n",
       "       [6., 3.]], dtype=float32)>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n1 = tf.constant([[3.0,1.5],[3.0,1.5]],tf.float32)\n",
    "n2 = tf.constant([[4.0,1.5],[3.0,1.5]],tf.float32)\n",
    "n3 = tf.add(n1,n2)\n",
    "n3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "24d64715",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.0\n",
      "(2, 2)\n",
      "<dtype: 'float32'>\n",
      "(2, 2)\n"
     ]
    }
   ],
   "source": [
    "print(n3.numpy()[1,1])\n",
    "# print(n3.value)\n",
    "print(n3.shape)\n",
    "print(n3.dtype)\n",
    "print(n3.get_shape())\n",
    "\n",
    "# print(n3.rank)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c4e5395b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<tf.Variable 'Variable:0' shape=(2, 2) dtype=float32, numpy=\n",
       " array([[3. , 1.5],\n",
       "        [3. , 1.5]], dtype=float32)>,\n",
       " <tf.Variable 'Variable:0' shape=(2, 2) dtype=float32, numpy=\n",
       " array([[4. , 1.5],\n",
       "        [3. , 1.5]], dtype=float32)>)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "#变量,前面是常量 \n",
    "v1 = tf.Variable([[3.0,1.5],[3.0,1.5]],tf.float32)\n",
    "v2 = tf.Variable([[4.0,1.5],[3.0,1.5]],tf.float32)\n",
    "v3 = tf.add(v1,v2)\n",
    "v1,v2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c1cc7c2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5bc0e6a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "v4 = tf.Variable(n1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "875889db",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'tensorflow' has no attribute 'Session'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_14280/3034498330.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;31m# 会话\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mhello\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconstant\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'hello,tf'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0msess\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSession\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhello\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[1;32mwith\u001b[0m \u001b[0msess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mas_defaults\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'tensorflow' has no attribute 'Session'"
     ]
    }
   ],
   "source": [
    "# 变量一般不赋初值, 一定要赋初值是用assign assign_add sub\n",
    "# 会话\n",
    "hello = tf.constant('hello,tf')\n",
    "sess = tf.Session()\n",
    "print(sess.run(hello))\n",
    "with sess.as_defaults():\n",
    "    print(hello.eval())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19f18131",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
